home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Source Code
/
C
/
Games
/
Pentominoes 2.0
/
Pent code
/
pent floating window.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-07-29
|
4KB
|
161 lines
#include "pent floating window.h"
#include "pent message.h"
#include "pent meat.h"
#include "pent graphics.h"
#include "window layer.h"
#include "program globals.h"
#include <Icons.h>
#define kLeftMargin 10
#define kRightMargin 10
#define kTopMargin 10
#define kBottomMargin 10
#define kNumIcons 12
#define kGapBetweenIcons 5
#define kIconHeight 32
#define kIconWidth 32
#define kFirstIconID 1000
#define kAnchoredPos 20
#define kUnanchoredPos 32
static Boolean gSetupDone=FALSE;
static Handle gFloatingIcon[kNumIcons];
void SetupTheFloatingWindow(WindowRef theWindow)
{
short i;
Point thePoint;
SetWindowHeight(theWindow, kTopMargin+kBottomMargin+kIconHeight);
SetWindowWidth(theWindow, kLeftMargin+kRightMargin+kIconWidth*kNumIcons+kGapBetweenIcons*(kNumIcons-1));
SetWindowAttributes(theWindow, kHasCloseBoxMask+kHasPaletteTitlebarMask);
SetWindowMaxDepth(theWindow, 8);
SetWindowDepth(theWindow, 8);
SetWindowIsFloat(theWindow, TRUE);
SetWindowTitle(theWindow, "\p");
SetWindowAutoCenter(theWindow, FALSE);
SetWindowIsModified(theWindow, FALSE);
thePoint.h=0;
thePoint.v=kUnanchoredPos;
SetWindowTopLeft(theWindow, thePoint);
gShowFloat=TRUE;
if (gSetupDone)
return;
gSetupDone=TRUE;
for (i=0; i<kNumIcons; i++)
GetIconSuite(&gFloatingIcon[i], kFirstIconID+i, svAllLargeData);
}
void OpenTheFloatingWindow(WindowRef theWindow)
{
if (gAnchorFloat)
MyMoveWindow(theWindow, 0, kAnchoredPos, FALSE);
}
void DisposeTheFloatingWindow(void)
{
if (IndWindowExistsQQ(kMainWindow))
gShowFloat=FALSE;
}
void MouseClickedInFloatingWindow(WindowRef theWindow, Point mouseLoc)
{
#pragma unused(theWindow)
short iconIndex;
Boolean iconIsHighlighted;
Rect iconRect;
GameError err;
if (mouseLoc.v<kTopMargin) return;
if (mouseLoc.v>(GetWindowHeight(theWindow)-kBottomMargin)) return;
if (mouseLoc.h<kLeftMargin) return;
if (mouseLoc.h>(GetWindowWidth(theWindow)-kRightMargin)) return;
mouseLoc.h-=kLeftMargin;
if (mouseLoc.h%(kIconWidth+kGapBetweenIcons)>kIconWidth) return;
iconIndex=mouseLoc.h/(kIconWidth+kGapBetweenIcons);
if (gPieceUsed[iconIndex]) return;
iconRect.left=kLeftMargin+iconIndex*(kIconWidth+kGapBetweenIcons);
iconRect.right=iconRect.left+kIconWidth;
iconRect.top=kTopMargin;
iconRect.bottom=kTopMargin+kIconHeight;
iconIsHighlighted=FALSE;
while (StillDown())
{
GetMouse(&mouseLoc);
if (PtInRect(mouseLoc, &iconRect))
{
if (!iconIsHighlighted)
{
iconIsHighlighted=TRUE;
PlotIconSuite(&iconRect, atAbsoluteCenter, ttSelected, gFloatingIcon[iconIndex]);
}
}
else
{
if (iconIsHighlighted)
{
iconIsHighlighted=FALSE;
PlotIconSuite(&iconRect, atAbsoluteCenter, ttNone, gFloatingIcon[iconIndex]);
}
}
}
if (iconIsHighlighted)
{
PlotIconSuite(&iconRect, atAbsoluteCenter, ttNone, gFloatingIcon[iconIndex]);
if ((err=PlacePiece(GetIndWindowRef(kMainWindow), iconIndex, &iconIndex))!=eNoError)
DisplayMessage(err);
}
}
void DrawTheFloatingWindow(WindowRef theWindow, short theDepth)
{
short i;
Rect iconRect;
DrawSoftWindowBorder(theWindow, theDepth, 0, FALSE);
iconRect.left=kLeftMargin;
iconRect.right=kLeftMargin+kIconWidth;
iconRect.top=kTopMargin;
iconRect.bottom=kTopMargin+kIconHeight;
for (i=0; i<kNumIcons; i++)
{
PlotIconSuite(&iconRect, atAbsoluteCenter, gPieceUsed[i] ? ttDisabled : ttNone, gFloatingIcon[i]);
iconRect.left+=kIconWidth+kGapBetweenIcons;
iconRect.right+=kIconWidth+kGapBetweenIcons;
}
}
void ToggleShowFloatingWindow(void)
{
Boolean nowShowing;
nowShowing=gShowFloat;
if (IndWindowExistsQQ(kMainWindow))
{
if (nowShowing)
CloseTheWindow(GetIndWindowRef(kFloatingWindow));
else
OpenTheIndWindow(kFloatingWindow, kOpenOldIfPossible);
}
gShowFloat=!nowShowing;
}
void ToggleAnchorFloatingWindow(void)
{
WindowRef theWindow;
theWindow=GetIndWindowRef(kFloatingWindow);
gAnchorFloat=!gAnchorFloat;
if (theWindow!=0L)
MyMoveWindow(theWindow, 0, gAnchorFloat ? kAnchoredPos : kUnanchoredPos, FALSE);
}